import i18n from 'i18next'
import {languageActionType} from "./languageaction";

export interface languageState{
    language:"en"|"zh",
    languagelist:{name:string,code:string}[]
}
const defaultState:languageState={
    language:"zh",
    languagelist:[
        {name:"中文",code:"zh"},
        {name:"English",code:"en"}
    ]
}
export default (state=defaultState,action:languageActionType)=>{
    if(action.type==="change_language"){
        const newState={...state,language:action.payload}
        i18n.changeLanguage(action.payload)
        return newState
    }
    return state;
}